<?php

namespace App\Http\Controllers;

use App\User;

use Illuminate\Http\Request;
use App\Http\Requests;
use Illuminate\Support\Facades\Input;

class UserController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function login(Request $request)
    {
        $request->session()->set("userName",null);
        $userName = Input::get("userName");
        if ($userName) {
            $password = Input::get("password");

            $userInfo = User::where("name",$userName)->first();
            if ($userInfo['password'] == encodePwd($password)) {
                $request->session()->set("userName",$userInfo);
                return redirect("/admin/lesson/index");
            } else {
                return redirect("/login");
            }
        }

        $data = array();
        return view("admin.login",$data);
    }

    public function logout(Request $request) {
        $request->session()->clear();
    }

}
